1430A - Number of Apartments - CodeForces Solution


brute force constructive algorithms math *900

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    if n in [1, 2, 4]:
        print(-1)
    else:
        if n % 3 == 0:
            print(n//3, 0, 0)
        elif n % 3 == 1:
            print((n-7)//3, 0, 1)
        else:
            print((n-5)//3, 1, 0)

C++ Code:

#include <bits/stdc++.h>
#include <deque>
#include<algorithm>
using namespace std;
using ll = long long;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define vi vector< int >
#define vl vector< ll >
#define mi map<int ,int>
#define ml map<ll,ll>
const int hell=1000000007;
//--------------------------------------------------//
            //--code from daksh_chhipa--//
//--------------------------------------------------// 
void showdq(deque<int> g)
{
    deque<int>::iterator it;
    for (it = g.begin(); it != g.end(); ++it)
        cout << '\t' << *it;
    cout << '\n';
}
bool isPerfectSquare(long long x)
{
    if (x >= 0) {
        long long sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;
   return (ceil(log2(n)) == floor(log2(n)));
}
unsigned countBits(unsigned int number)
{   
    return (int)log2(number)+1;
}
void counterint(int x){
    if(x>0){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
}
void counteransh(int x){
    if(x>0){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
}
//for(int i=0;i<n;i++){cin>>array[i];}
//for(int i=0;i<n;i++){int x; cin>>x; v.push_back(x);}
string s;
int main(){
    int t;
    cin>>t;
    while(t--){
int n,counter=0,even=0,odd=0;
cin>>n;
int array[n];
//3*i+5*j=//2x +5y+7z=n
//for(int i=0;i<n;i++){cin>>array[i];}
if(n%7==0){
    cout<<0<<" "<<0<<" "<<n/7<<endl;
}
else if(n%3==0){
        cout<<n/3<<" "<<0<<" "<<0<<endl;
}
else if(n%5==0){
        cout<<0<<" "<<n/5<<" "<<0<<endl;
}
else{
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if((n-(3*i+5*j))%7==0  && (n-(3*i+5*j))>=0){
                cout<<i<<" "<<j<<" "<<(n-(3*i+5*j))/7<<endl;
                counter=1;
                break;
            }
               else if((n-(5*i+7*j))%3==0 && (n-(5*i+7*j))>=0){
                cout<<(n-(5*i+7*j))/3<<" "<<i<<" "<<j<<endl;
                  counter=1;
                break;
            } 
            else if((n-(3*i+7*j))%3==0 && (n-(3*i+7*j))>=0){
                cout<<i<<" "<<(n-(3*i+7*j))/5<<" "<<j<<endl;
                  counter=1;
                break;
            }
        }
        if(counter==1){
            break;
        }
    }
    if(counter==0){
        cout<<"-1"<<endl;
    }
}

}
    return 0;
}


Comments

Submit
0 Comments
More Questions

1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains
664A - Complicated GCD
1635D - Infinite Set
1462A - Favorite Sequence
1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square
766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums